using System.Collections.Generic;
using Game.Core;
using Game.Main.Model;
using Game.Main.View;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class QueuingMachineItem : BaseItem
	{
		private Transform cameraTrans;

		private List<int> numList = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

		private List<int> createNumList = new List<int>();

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			if (data.intList != null)
			{
				createNumList = data.intList;
			}
		}

		public override void ResetState()
		{
			base.ResetState();
			CreateNumberCard();
		}

		public void CreateNumberCard()
		{
			if (base.itemData.createIds == null || childItems.Count > 0 || createNumList.Count >= numList.Count)
			{
				return;
			}
			for (int i = 0; i < numList.Count; i++)
			{
				if (!createNumList.Contains(numList[i]))
				{
					BaseItem baseItem = Singleton<Scene>.Instance.CreateItem(base.itemData.createIds[0], model.Find("CreatePoint").position, 0);
					if (baseItem.itemData.scriptType == 98)
					{
						((NumberCardItem)baseItem).InitNumber(numList[i]);
						createNumList.Add(numList[i]);
					}
					AddCreateItem(baseItem);
					AttachItem(baseItem, DepthType.Front, AttachType.Place, false);
					break;
				}
			}
		}

		public override void RemoveCreateItem(BaseItem item)
		{
			base.RemoveCreateItem(item);
			if (item.itemData.scriptType == 98)
			{
				createNumList.RemoveAt(((NumberCardItem)item).GetNum());
			}
		}

		public override void ReleaseAttachItem(BaseItem item)
		{
			base.ReleaseAttachItem(item);
			CreateNumberCard();
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["48"] = PackIntList(createNumList);
		}
	}
}
